#!/usr/bin/env python
# coding: utf-8
# $Id$
# hello world producer

import parallels
from twisted.internet import defer, reactor

def response(text):
    print 'got response:', text
    reactor.stop()

def main():
    # Parallels will call spawnProcess() and execute
    # ex1consumer.py, and set up a bidirectional pipe
    # for the communication between them.
    producer = parallels.Parallels('ex1consumer.py')

    # I create a deferred because I want to be able to
    # read the response returned by the parallel program
    # ex1consumer.py.
    #
    # If you don't need it, just call producer.put()
    # without a deferred on it. In this case, the data
    # will just be sent and you'll never get the response.

    deferred = producer.put('hello world')
    deferred.addCallback(response)

if __name__ == '__main__':
    reactor.callWhenRunning(main)
    reactor.run()
